//支付宝支付
var type = '';
//获取订单信息
/**
 * types支付产品类型（1、物流师题库教材；2、学习频道；3、天津培训包课程；4、导师online课程；5、课程频道；6、认证频道 ）
 *subtype类型（一、学习频道（1、精品课程；2、Mooc课程；3、学习任务知识点）二、认证（1、报名费；2、考试费,3纸质证书费用））
 *id:如果时课程就是课程id，如果时岗位就是岗位id
 *  */
function getOrderNumber(types, id, subtype) {

	type = types;
	showProgress();

	var params = {
		uid : $api.getStorage("cfnetppuid"),
		cid : id,
		types : types,
		subtype : subtype,
		nums : 1
	};
	//			alert(JSON.stringify(params));
	//		return;
	cfnetppPOST(url_buypubpro, params, true, function(data, status) {
		hideProgress();
		if (data) {
			if (data.code = 200) {
				aliPayPlus_data(data.data,subtype);
			}
		} else {
			alert('网络有问题');
		}
	})
}
function aliPayConfig(aliPay,callBack) {
	aliPay.config({
		appId: '2019041963935883',
		rsaPriKey: 'MIIEpQIBAAKCAQEA0Y7BvbVP2qjtfP8J8FalKXgxamGqNUhfEIdshvfrgzZQHqe6B6vEcEnm3y6pka9XCnSZnwsRUiDGDsjV3m5nQ4YFtqK5OH7Xv3b6xLMZ5Zr4i66Eb/yPbiSvLP/hc3EVAr2rFIT4630TMe70v5Vz7ZouUS3oh0yJpdVU418XyPtcXvSb5cAoGyUItZtHESiB41tVvBk+vs9a2t84+BCjLlWr7HJ9PApC7DDeI49A7TPHfKHSP9EAS1fDZZqjSn0eMbCL+yC52Bg5ao4L1Re6ec3+7vGfD9Lq89Hg32Y9dXcheUhrNEOXppa2VpjfUsChSwVOTXcy5f0bVBokZe35JQIDAQABAoIBAQDPm22HY3wkNZ1qa0TObRidd+0E5pL4zKUZvAChyjXxvTos1KAxf1NSp3RpgVIO+bXyrseO0CktwzhUZ1WyUpBNThaU9KspNEjL77TKcGFknl5EC/Y69+ylAwTlQO97LfnRyFQYNRBiRHxiyMiCkS7Tox7l3+RxPjtUJoA97fSjb8/q7cZVZaftYBIhJ2eWN206WebHEpCiO/Kr+3bjqtpKrYTjjkrm4xORUivHGl6V/ZykCvSV5XMEGFRq0Du32kNAgDR0GLRIWg+JWZMW2yPGWkw+CixA7OCg5s9gYyiVaKSGBmK7YEYbEI6BabjrMPbsEVc5+l/26T6jtjNOTnJhAoGBAO0EnGD8SfOq5mr7gN5oiPMEtFk8wZSFouNXl1PorQmGMylBE082u7xouq1crdtN66rDPYxaLigSyslM69t5rhoi9N6xGFSHGhbJiP7vo2rxnZjrap3NGsD6djsmJruRJu7dcDFsneOsHXs8TmrGZb1zdrQwLizUjafpz70ojGINAoGBAOJXJe7/sx4E4TUCxL0d65VIIMYW7/PLZLpylQiyB8Q75DLedYe7ixIXGq37dVPYolnC8GOXbMCg4dNuj2yw8jy90LlnjXZ9y176LAYsBvfI9GWuZhOiVHtJArHV3QuwjddSAqv/mc4xf3ddrotRnEI8E3bjKiizid62lhA11uV5AoGBAJESHmkaYmU7OFdI4yK+Vvxv57crAc1XUlDWPvCD3M2Uj2Hzy87TUGtMqt4LePpfIhzd7aEnXVL31ZkKdN5cBt1Gghx/xsWN/8Dsz+ZCZQLDKlP728EEVhjB9HXVryVk/bB8ZvxJYAaHRXA1hEXEc2dW8dPuHYUhACdDa/x6ghpNAoGARobLPiaU5IS2u/Lp5Nfe4XxBIhhhmoDFGUe84qG+w8m5uJQS4UFx+ygR2yagj4jQRdH1X8L+UyOOWnh33nFgecbXs/3tWX+nECg58Y5keW83oDtweSu60VOVsF4oa40PFYnrZTbW8SYBRut9CNJcM1NO6VutdlNDYY9ZQSHVnVkCgYEAtPILzVDLOxbxaXfT7KL3X8PTMFZ0mqBhPwQMYX0v+QnXh7OzW5If1YE/Q51bIX2Ohr/VjZj4VUjhgBWJL8sWmPjEKw3hGTKy40fBd4h2JM3OuRbyxFRu25HWZcIqQcVfihrCR6JC8Xn/mNFbBEPmqu9ZOF/ki2E7xXtX/jxDcZk=',
	},callBack);
}
/**
 * 阿里支付
 * @param data
 * @param callback
 */
function aliPay(data,callback) {
	var aliPay = api.require('aliPayPlus');
	aliPayConfig(aliPay,function (ret,err) {
		console.log(JSON.stringify(ret));
		if(ret.status){
			aliPay.pay({
				subject: data.subject,
				body: data.body,
				amount: data.amount,
				tradeNO: data.tradeNO,
				rsa2:true,
				sandbox: true
			}, callback);
		}
	});
}
//调用支付宝
function aliPayPlus_data(data,subtype) {
	var aliPay = api.require('aliPay');
	aliPay.config({
		partner : '2088701715750690',
		seller : 'chinalogis@126.com',
		rsaPubKey : 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9ipCKy9Jdh+MyvD6/LQwm3A0cIQzGTdBxtQryaQ1tRon9aKYMUeJiT0UpOtyXZrOQ4HSOVY/GR+I+jd+mHPPu/24msup6HW5MF1YhcBslUllYvjaVLXUDFgLRUJRjEXutupMRWrda4Cnx1gQeqiznObyZ7uc44mXXqIDCQTE8dQIDAQAB',
		notifyURL : url_AddPay_notify, //支付成功回调地址
		rsaPriKey : 'MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAL2KkIrL0l2H4zK8Pr8tDCbcDRwhDMZN0HG1CvJpDW1Gif1opgxR4mJPRSk63Jdms5DgdI5Vj8ZH4j6N36Yc8+7/biay6nodbkwXViFwGyVSWVi+NpUtdQMWAtFQlGMRe626kxFat1rgKfHWBB6qLOc5vJnu5zjiZdeogMJBMTx1AgMBAAECgYEAuHK/dlIixSIX1qeZ6DDOQoKhv13qMJBI6F5l6MCScGTUo+XSsOp+g2zgwN6nDC7FT5cd1eUtpKcPZBBsNBq4xYqEOepQimdXN5W3tuW6wMwMdV0Oyvoa1ry3R1saywInBfMxKZ4fhUA+TAGTCckzmCZxa3rth4rSBqRDckt3XAECQQD9yx+RzWAOpjJ/lU0UUsKr+uOYT2YHrgvzUGBSfrnD+e/GRjJ7KLcSY+I4ks7Bo1v11BRmDjiCh7z/E/1QCLWtAkEAvzBu27V8/xqyhjkB9+gWEQ6vTCoS+zyvn35nKBQ5TpcpGr4MJ5Sp14WHt0PLntFXhiZcxDgsNNzgxSEmgPuq6QJBAO7XdgJU8Q1YQzXmX/+8UxBesEnqju6zUPPOtJduQ4y3bnt+HIvjKUbZUVBEeOeqwSR8TiYtQ+kzrR2wxjfHupECQAEJ3lBLOBaaqoWYIa6bECOflMwxHlFHDx0qrpzFH1qR76M5jQ9Z+2I0U3xnXd/K+1K7Op3GQFc5K+9mMrNYqqECQQCtDwta7SGq8fDhemkK8mfk1/tUzs/s5BKVXG0qB0Bc+SdCrhZn02BprcxFQIZbcTahhmxm26/CGcbMBBPZ2TNn',
	}, function(ret, err) {
		//	alert(JSON.stringify(ret));
		if (ret.status == 1) {
			aliPay.pay({
				subject : data.name,
				body : data.name,
				amount : data.moneyShow,//价格
				//								amount : '0.01',
				tradeNO : data.orderinfo//订单号
			}, function(ret, err) {
				if (ret.code == 9000) {
					setAddPay(data,subtype);
				} else if (ret.code == 6001) {
					api.sendEvent({
						name : 'close_frame'
					});

				} else {
					ShowToast("支付异常，请重新支付");
				}
			});
		}
	});
}

/**
 *
 *支付成功之后修改支付信息
 *quarter_id       岗位id
 *paytype	支付方式 1线下支付 2支付宝支付
 *  */
function setAddPay(data,subtype) {
	var url = '';
	var params = '';
	if (type == 6) {//认证
		url = url_AddPay;
		params = {
			uid : $api.getStorage("cfnetppuid"),
			quarter_id : $api.getStorage("jobs_id"),
			jid : "52",
			orderinfo:data.orderinfo,
			subtype:subtype,
			paytype : "2"
		};
	} else if (type == 5) {//学习
		url = url_updatepaystate;
		params = {
			uid : $api.getStorage("cfnetppuid"),
			out_trade_no : data.orderinfo,
			jid : $api.getStorage("cfnetppjxid"),
			total_fee : data.moneyShow,
			trade_status : 'TRADE_SUCCESS ',
			paytype : "2"
		};
	} else if (type == 7) {//申请纸质证书
		url = url_addPayCate;
		params = {
			uid : $api.getStorage("cfnetppuid"),
			quarter_id : $api.getStorage("jobs_id"),
			jid : "52",
			paytype : "2"
		};
	}

	//		alert(JSON.stringify(params));
	cfnetppPOST(url, params, true, function(data, status) {
		if (type == 6) {
			params['message'] = '支付' + $api.getStorage("jobs") + '认证费用￥' + $api.getStorage("pay_money");
			params['vid'] = $api.getStorage("jobs_id");
			SendBusinessOperationsLogNotifi('岗位支付页', '123', params, params, '', data, '岗位报名之后修改岗位信息接口', '123-01')
		} else if (type == 5) {
			params['message'] = $api.getStorage("add_coursename");
			SendBusinessOperationsLogNotifi('选课列表页', '079', params, params, '', data, '选课中心修改订单状态接口', '079-04')
		}

		if (type == 6) {
			params['message'] = '支付' + $api.getStorage("jobs") + '认证费用￥' + $api.getStorage("pay_money");
			params['vid'] = $api.getStorage("jobs_id");
			SendBusinessOperationsLogNotifi('岗位支付页', '123', params, params, '', data, '岗位报名之后修改岗位信息接口', '123-01')
		} else if (type == 5) {
			params['message'] = $api.getStorage("add_coursename");
			SendBusinessOperationsLogNotifi('选课中心课程详情页', '079', params, params, '', data, '选课中心修改订单状态接口', '081-01')
		}

		//		alert("支付成功回调" + JSON.stringify(data));
		if (data) {
			if (data.code = 200) {
				if (type == 6) {//认证
					//支付成功跳转到认证页
					api.sendEvent({
						name : 'jumpPage',
						extra : {
							page : 3
						}
					});
					api.closeWin({
						name : "MyAPPly"
					});
					api.closeWin({
						name : "Detaila"
					});
					//刷新我的认证
					api.sendEvent({
						name : 'sendrefreshdata'
					});
					api.closeWin({
						url : "Upload_Order"
					});
				} else if (type == 5) {//课程

					addCourse();
				} else if (type == 7) {//支付纸质证书

					closewind();
				}
			}
		} else {
			alert('网络有问题');
		}
	})
}

//显示加载框
function showProgress() {
	api.showProgress({
		style : 'default',
		animationType : 'fade',
		title : '',
		text : '生成订单中…',
		modal : false
	});
}